namespace QMVnSoft.Invoices
{
    using QMVnSoft;
    using QMVnSoft.Controls;
    using QMVnSoft.Controls.ChildGridControls;
    using QMVnSoft.Properties;
    using System;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Windows.Forms;

    public class FormPaymentDetail : FormControl
    {
        private ToolStripButton btnCancel;
        private ToolStripButton btnClose;
        private ToolStripButton btnRefresh;
        private ToolStripButton btnSave;
        private DataGridViewTextBoxColumn Column1;
        private DataGridViewCheckBoxColumn Column10;
        private DataGridViewTextBoxColumn Column11;
        private DataGridViewTextBoxColumn Column12;
        private DataGridViewTextBoxColumn Column13;
        private DataGridViewTextBoxColumn Column14;
        private DataGridViewTextBoxColumn Column15;
        private NumericColumn Column16;
        private NumericColumn Column17;
        private NumericColumn Column18;
        private NumericColumn Column19;
        private DataGridViewTextBoxColumn Column2;
        private NumericColumn Column20;
        private DataGridViewCheckBoxColumn Column21;
        private DataGridViewTextBoxColumn Column3;
        private DataGridViewTextBoxColumn Column4;
        private DataGridViewTextBoxColumn Column5;
        private DataGridViewTextBoxColumn Column6;
        private NumericColumn Column7;
        private NumericColumn Column8;
        private NumericColumn Column9;
        private IContainer components;
        private GridControl grdDetail;
        private GridControl grdMaster;
        private SplitContainer GridContainer;
        private string is_MasterInvoiceOrder;
        private HeaderCheck oDetailHeader;
        private DataTable oDetailTable;
        private AppInvoiceLib oAppInvoiceLib;
        private DataRow oMasterRow;
        private DataTable oMasterTable;
        private ToolStripSeparator tbrSep01;
        private ToolStripSeparator tbrSep02;
        private ToolStripSeparator tbrSep03;
        private ToolStrip Toolbars;

        public FormPaymentDetail(AppInvoiceLib po_AppInvoiceLib, string ps_MasterInvoiceOrder)
        {
            this.InitializeComponent();
            this.grdMaster.AutoGenerateColumns = false;
            this.grdDetail.AutoGenerateColumns = false;
            this.AppInvoiceParameters = po_AppInvoiceLib;
            this.MasterInvoiceOrder = ps_MasterInvoiceOrder;
            if (!this.AppInvoiceParameters.BilingualUsed)
            {
                this.grdMaster.Columns[4].Visible = false;
                this.grdDetail.Columns[3].Visible = false;
            }
            this.oDetailHeader = new HeaderCheck();
            this.Column21.HeaderCell = this.oDetailHeader;
            this.Column21.HeaderText = "";
            this.oDetailHeader.OnCheckBoxClicked += new CheckBoxClickedHandler(this.oDetailHeader_OnCheckBoxClicked);
            this.FillData();
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.FillDetailData();
        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            base.Close();
        }

        private void btnSave_Click(object sender, EventArgs e)
        {
            if ((this.oDetailTable != null) && (this.oDetailTable.Rows.Count != 0))
            {
                this.Save();
            }
        }

        private bool CheckReadOnly()
        {
            int num = this.AppInvoiceParameters.AppInvoiceMethod.InvoiceStatus(AppInstance.Subsidiary, this.AppInvoiceParameters.TransactionType, AppInstance.UserName, this.MasterInvoiceOrder);
            if (((num != 7) && (num != 8)) && (num != 9))
            {
                return false;
            }
            return true;
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing && (this.components != null))
            {
                this.components.Dispose();
            }
            base.Dispose(disposing);
        }

        private void FillData()
        {
            this.oMasterTable = this.AppInvoiceParameters.AppInvoiceMethod.GetPaymentMasterTable(this.MasterInvoiceOrder);
            this.grdMaster.DataSource = new BindingSource(this.oMasterTable, this.oMasterTable.TableName);
            bool flag = this.CheckReadOnly();
            this.Column10.ReadOnly = flag;
            this.Column20.ReadOnly = flag;
            this.Column21.ReadOnly = flag;
            this.btnSave.Enabled = !flag;
            this.btnCancel.Enabled = !flag;
        }

        private void FillDetailData()
        {
            if (this.MasterDataRow != null)
            {
                this.oDetailTable = this.AppInvoiceParameters.AppInvoiceMethod.GetPaymentDetailTable(AppInstance.Subsidiary, this.MasterInvoiceOrder, this.MasterDataRow["Ma_Bp"], this.MasterDataRow["Ma_Hd"], this.MasterDataRow["Ma_Dt"], this.MasterDataRow["No_Co"], this.MasterDataRow["Tk"], this.MasterDataRow["Ma_Tte"], this.MasterDataRow["Han_Tt"], this.MasterDataRow["Ngay_Ct"]);
                this.grdDetail.DataSource = new BindingSource(this.oDetailTable, this.oDetailTable.TableName);
            }
        }

        private void grdDetail_CellEndEdit(object sender, DataGridViewCellEventArgs e)
        {
            if ((e.ColumnIndex != 10) && (e.ColumnIndex == 9))
            {
                this.Sum();
            }
        }

        private void grdMaster_CellEndEdit(object sender, DataGridViewCellEventArgs e)
        {
            if (e.ColumnIndex == 9)
            {
                foreach (DataRow row in this.oDetailTable.Rows)
                {
                    if (row.RowState != DataRowState.Deleted)
                    {
                        if ((bool) this.MasterDataRow["Marked"])
                        {
                            row["Tien_Nt"] = row["Tien_Nt2"];
                            row["Tien"] = row["Tien2"];
                            row["Marked"] = true;
                        }
                        else
                        {
                            row["Tien_Nt"] = 0;
                            row["Tien"] = 0;
                            row["Marked"] = false;
                        }
                    }
                }
                this.Sum();
            }
        }

        private void grdMaster_CellEnter(object sender, DataGridViewCellEventArgs e)
        {
            if ((this.grdMaster.CurrentRow != null) && (this.grdMaster.CurrentRow.DataBoundItem != null))
            {
                this.MasterDataRow = ((DataRowView) this.grdMaster.CurrentRow.DataBoundItem).Row;
            }
        }

        private void InitializeComponent()
        {
            System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle1 = new System.Windows.Forms.DataGridViewCellStyle();
            System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle2 = new System.Windows.Forms.DataGridViewCellStyle();
            System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle3 = new System.Windows.Forms.DataGridViewCellStyle();
            System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle4 = new System.Windows.Forms.DataGridViewCellStyle();
            System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle5 = new System.Windows.Forms.DataGridViewCellStyle();
            System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle6 = new System.Windows.Forms.DataGridViewCellStyle();
            System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle7 = new System.Windows.Forms.DataGridViewCellStyle();
            System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle8 = new System.Windows.Forms.DataGridViewCellStyle();
            this.Toolbars = new System.Windows.Forms.ToolStrip();
            this.btnRefresh = new System.Windows.Forms.ToolStripButton();
            this.tbrSep01 = new System.Windows.Forms.ToolStripSeparator();
            this.btnSave = new System.Windows.Forms.ToolStripButton();
            this.tbrSep02 = new System.Windows.Forms.ToolStripSeparator();
            this.btnCancel = new System.Windows.Forms.ToolStripButton();
            this.tbrSep03 = new System.Windows.Forms.ToolStripSeparator();
            this.btnClose = new System.Windows.Forms.ToolStripButton();
            this.GridContainer = new System.Windows.Forms.SplitContainer();
            this.grdMaster = new QMVnSoft.Controls.GridControl();
            this.Column1 = new System.Windows.Forms.DataGridViewTextBoxColumn();
            this.Column2 = new System.Windows.Forms.DataGridViewTextBoxColumn();
            this.Column3 = new System.Windows.Forms.DataGridViewTextBoxColumn();
            this.Column4 = new System.Windows.Forms.DataGridViewTextBoxColumn();
            this.Column5 = new System.Windows.Forms.DataGridViewTextBoxColumn();
            this.Column6 = new System.Windows.Forms.DataGridViewTextBoxColumn();
            this.Column7 = new QMVnSoft.Controls.ChildGridControls.NumericColumn();
            this.Column8 = new QMVnSoft.Controls.ChildGridControls.NumericColumn();
            this.Column9 = new QMVnSoft.Controls.ChildGridControls.NumericColumn();
            this.Column10 = new System.Windows.Forms.DataGridViewCheckBoxColumn();
            this.grdDetail = new QMVnSoft.Controls.GridControl();
            this.Column11 = new System.Windows.Forms.DataGridViewTextBoxColumn();
            this.Column12 = new System.Windows.Forms.DataGridViewTextBoxColumn();
            this.Column13 = new System.Windows.Forms.DataGridViewTextBoxColumn();
            this.Column14 = new System.Windows.Forms.DataGridViewTextBoxColumn();
            this.Column15 = new System.Windows.Forms.DataGridViewTextBoxColumn();
            this.Column16 = new QMVnSoft.Controls.ChildGridControls.NumericColumn();
            this.Column17 = new QMVnSoft.Controls.ChildGridControls.NumericColumn();
            this.Column18 = new QMVnSoft.Controls.ChildGridControls.NumericColumn();
            this.Column19 = new QMVnSoft.Controls.ChildGridControls.NumericColumn();
            this.Column20 = new QMVnSoft.Controls.ChildGridControls.NumericColumn();
            this.Column21 = new System.Windows.Forms.DataGridViewCheckBoxColumn();
            this.Toolbars.SuspendLayout();
            this.GridContainer.Panel1.SuspendLayout();
            this.GridContainer.Panel2.SuspendLayout();
            this.GridContainer.SuspendLayout();
            ((System.ComponentModel.ISupportInitialize)(this.grdMaster)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.grdDetail)).BeginInit();
            this.SuspendLayout();
            // 
            // Toolbars
            // 
            this.Toolbars.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
            this.btnRefresh,
            this.tbrSep01,
            this.btnSave,
            this.tbrSep02,
            this.btnCancel,
            this.tbrSep03,
            this.btnClose});
            this.Toolbars.Location = new System.Drawing.Point(0, 0);
            this.Toolbars.Name = "Toolbars";
            this.Toolbars.Size = new System.Drawing.Size(794, 25);
            this.Toolbars.TabIndex = 0;
            this.Toolbars.Text = "Toolbars";
            // 
            // btnRefresh
            // 
            this.btnRefresh.Image = global::QMVnSoft.Properties.Resources.REFRESH;
            this.btnRefresh.ImageTransparentColor = System.Drawing.Color.Magenta;
            this.btnRefresh.Name = "btnRefresh";
            this.btnRefresh.Size = new System.Drawing.Size(66, 22);
            this.btnRefresh.Text = "Refresh";
            this.btnRefresh.ToolTipText = "Refresh";
            // 
            // tbrSep01
            // 
            this.tbrSep01.Name = "tbrSep01";
            this.tbrSep01.Size = new System.Drawing.Size(6, 25);
            // 
            // btnSave
            // 
            this.btnSave.Image = global::QMVnSoft.Properties.Resources.SAVE1;
            this.btnSave.ImageTransparentColor = System.Drawing.Color.Magenta;
            this.btnSave.Name = "btnSave";
            this.btnSave.Size = new System.Drawing.Size(47, 22);
            this.btnSave.Text = "Lưu";
            this.btnSave.ToolTipText = "Save";
            this.btnSave.Click += new System.EventHandler(this.btnSave_Click);
            // 
            // tbrSep02
            // 
            this.tbrSep02.Name = "tbrSep02";
            this.tbrSep02.Size = new System.Drawing.Size(6, 25);
            // 
            // btnCancel
            // 
            this.btnCancel.Image = global::QMVnSoft.Properties.Resources.CANCEL;
            this.btnCancel.ImageTransparentColor = System.Drawing.Color.Magenta;
            this.btnCancel.Name = "btnCancel";
            this.btnCancel.Size = new System.Drawing.Size(47, 22);
            this.btnCancel.Text = "Xóa";
            this.btnCancel.ToolTipText = "Cancel";
            this.btnCancel.Click += new System.EventHandler(this.btnCancel_Click);
            // 
            // tbrSep03
            // 
            this.tbrSep03.Name = "tbrSep03";
            this.tbrSep03.Size = new System.Drawing.Size(6, 25);
            this.tbrSep03.Visible = false;
            // 
            // btnClose
            // 
            this.btnClose.Image = global::QMVnSoft.Properties.Resources.CLOSE;
            this.btnClose.ImageTransparentColor = System.Drawing.Color.Magenta;
            this.btnClose.Name = "btnClose";
            this.btnClose.Size = new System.Drawing.Size(58, 22);
            this.btnClose.Text = "Thoát";
            this.btnClose.ToolTipText = "Close";
            this.btnClose.Visible = false;
            this.btnClose.Click += new System.EventHandler(this.btnClose_Click);
            // 
            // GridContainer
            // 
            this.GridContainer.Dock = System.Windows.Forms.DockStyle.Fill;
            this.GridContainer.IsSplitterFixed = true;
            this.GridContainer.Location = new System.Drawing.Point(0, 25);
            this.GridContainer.Name = "GridContainer";
            this.GridContainer.Orientation = System.Windows.Forms.Orientation.Horizontal;
            // 
            // GridContainer.Panel1
            // 
            this.GridContainer.Panel1.Controls.Add(this.grdMaster);
            // 
            // GridContainer.Panel2
            // 
            this.GridContainer.Panel2.Controls.Add(this.grdDetail);
            this.GridContainer.Size = new System.Drawing.Size(794, 509);
            this.GridContainer.SplitterDistance = 238;
            this.GridContainer.SplitterWidth = 1;
            this.GridContainer.TabIndex = 3;
            // 
            // grdMaster
            // 
            this.grdMaster.AllowUserToAddRows = false;
            this.grdMaster.AllowUserToDeleteRows = false;
            this.grdMaster.CheckAutoSize = true;
            this.grdMaster.CheckColor = false;
            this.grdMaster.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
            this.grdMaster.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
            this.Column1,
            this.Column2,
            this.Column3,
            this.Column4,
            this.Column5,
            this.Column6,
            this.Column7,
            this.Column8,
            this.Column9,
            this.Column10});
            this.grdMaster.Dock = System.Windows.Forms.DockStyle.Fill;
            this.grdMaster.Font = new System.Drawing.Font("Arial", 8.25F);
            this.grdMaster.Location = new System.Drawing.Point(0, 0);
            this.grdMaster.Name = "grdMaster";
            this.grdMaster.Size = new System.Drawing.Size(794, 238);
            this.grdMaster.TabIndex = 0;
            this.grdMaster.CellEndEdit += new System.Windows.Forms.DataGridViewCellEventHandler(this.grdMaster_CellEndEdit);
            this.grdMaster.CellEnter += new System.Windows.Forms.DataGridViewCellEventHandler(this.grdMaster_CellEnter);
            // 
            // Column1
            // 
            this.Column1.DataPropertyName = "Ngay_Ct";
            this.Column1.HeaderText = "Ngày";
            this.Column1.Name = "Column1";
            this.Column1.ReadOnly = true;
            this.Column1.Resizable = System.Windows.Forms.DataGridViewTriState.False;
            this.Column1.Width = 62;
            // 
            // Column2
            // 
            this.Column2.DataPropertyName = "So_Ct";
            this.Column2.HeaderText = "Số";
            this.Column2.Name = "Column2";
            this.Column2.ReadOnly = true;
            this.Column2.Width = 68;
            // 
            // Column3
            // 
            this.Column3.DataPropertyName = "Ten_Dt";
            this.Column3.HeaderText = "Đối tượng";
            this.Column3.Name = "Column3";
            this.Column3.ReadOnly = true;
            this.Column3.Width = 155;
            // 
            // Column4
            // 
            this.Column4.DataPropertyName = "Dien_Giai";
            this.Column4.HeaderText = "Diễn giải (VN)";
            this.Column4.Name = "Column4";
            this.Column4.ReadOnly = true;
            this.Column4.Width = 108;
            // 
            // Column5
            // 
            this.Column5.DataPropertyName = "Desc_EN";
            this.Column5.HeaderText = "Diễn giải (EN)";
            this.Column5.Name = "Column5";
            this.Column5.ReadOnly = true;
            this.Column5.Width = 108;
            // 
            // Column6
            // 
            this.Column6.DataPropertyName = "Ma_Tte";
            this.Column6.HeaderText = "Ttệ";
            this.Column6.Name = "Column6";
            this.Column6.ReadOnly = true;
            this.Column6.Resizable = System.Windows.Forms.DataGridViewTriState.False;
            this.Column6.Width = 30;
            // 
            // Column7
            // 
            this.Column7.DataPropertyName = "Ty_Gia";
            dataGridViewCellStyle1.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleRight;
            this.Column7.DefaultCellStyle = dataGridViewCellStyle1;
            this.Column7.HeaderText = "Tỷ giá";
            this.Column7.Name = "Column7";
            this.Column7.ReadOnly = true;
            this.Column7.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
            this.Column7.UserTextNumericFormat  = QMVnSoft.AppInstance.TextNumericFormat.ExchangeRate;
            this.Column7.Width = 60;
            // 
            // Column8
            // 
            this.Column8.DataPropertyName = "Tien_Nt0";
            dataGridViewCellStyle2.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleRight;
            this.Column8.DefaultCellStyle = dataGridViewCellStyle2;
            this.Column8.HeaderText = "Tiền";
            this.Column8.Name = "Column8";
            this.Column8.ReadOnly = true;
            this.Column8.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
            this.Column8.UserTextNumericFormat  = QMVnSoft.AppInstance.TextNumericFormat.ForeignAmount;
            this.Column8.Width = 70;
            // 
            // Column9
            // 
            this.Column9.DataPropertyName = "Tien_Nt";
            dataGridViewCellStyle3.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleRight;
            this.Column9.DefaultCellStyle = dataGridViewCellStyle3;
            this.Column9.HeaderText = "Thanh toán";
            this.Column9.Name = "Column9";
            this.Column9.ReadOnly = true;
            this.Column9.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
            this.Column9.UserTextNumericFormat  = QMVnSoft.AppInstance.TextNumericFormat.ForeignAmount;
            this.Column9.Width = 70;
            // 
            // Column10
            // 
            this.Column10.DataPropertyName = "Marked";
            this.Column10.HeaderText = "";
            this.Column10.Name = "Column10";
            this.Column10.Resizable = System.Windows.Forms.DataGridViewTriState.False;
            this.Column10.Width = 20;
            // 
            // grdDetail
            // 
            this.grdDetail.AllowUserToAddRows = false;
            this.grdDetail.AllowUserToDeleteRows = false;
            this.grdDetail.CheckAutoSize = true;
            this.grdDetail.CheckColor = false;
            this.grdDetail.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
            this.grdDetail.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
            this.Column11,
            this.Column12,
            this.Column13,
            this.Column14,
            this.Column15,
            this.Column16,
            this.Column17,
            this.Column18,
            this.Column19,
            this.Column20,
            this.Column21});
            this.grdDetail.Dock = System.Windows.Forms.DockStyle.Fill;
            this.grdDetail.Font = new System.Drawing.Font("Arial", 8.25F);
            this.grdDetail.Location = new System.Drawing.Point(0, 0);
            this.grdDetail.Name = "grdDetail";
            this.grdDetail.Size = new System.Drawing.Size(794, 270);
            this.grdDetail.TabIndex = 0;
            this.grdDetail.CellEndEdit += new System.Windows.Forms.DataGridViewCellEventHandler(this.grdDetail_CellEndEdit);
            // 
            // Column11
            // 
            this.Column11.DataPropertyName = "Ngay_Ct";
            this.Column11.HeaderText = "Ngày";
            this.Column11.Name = "Column11";
            this.Column11.ReadOnly = true;
            this.Column11.Resizable = System.Windows.Forms.DataGridViewTriState.False;
            this.Column11.Width = 62;
            // 
            // Column12
            // 
            this.Column12.DataPropertyName = "So_Ct";
            this.Column12.HeaderText = "Số";
            this.Column12.Name = "Column12";
            this.Column12.ReadOnly = true;
            this.Column12.Width = 68;
            // 
            // Column13
            // 
            this.Column13.DataPropertyName = "Dien_Giai";
            this.Column13.HeaderText = "Diễn giải (VN)";
            this.Column13.Name = "Column13";
            this.Column13.ReadOnly = true;
            // 
            // Column14
            // 
            this.Column14.DataPropertyName = "Desc_EN";
            this.Column14.HeaderText = "Diễn giải (EN)";
            this.Column14.Name = "Column14";
            this.Column14.ReadOnly = true;
            this.Column14.Width = 99;
            // 
            // Column15
            // 
            this.Column15.DataPropertyName = "Han_Tt";
            this.Column15.HeaderText = "Hạn T.toán";
            this.Column15.Name = "Column15";
            this.Column15.ReadOnly = true;
            this.Column15.Resizable = System.Windows.Forms.DataGridViewTriState.False;
            this.Column15.Width = 62;
            // 
            // Column16
            // 
            this.Column16.DataPropertyName = "Ty_Gia";
            dataGridViewCellStyle4.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleRight;
            this.Column16.DefaultCellStyle = dataGridViewCellStyle4;
            this.Column16.HeaderText = "Tỷ giá";
            this.Column16.Name = "Column16";
            this.Column16.ReadOnly = true;
            this.Column16.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
            this.Column16.UserTextNumericFormat  = QMVnSoft.AppInstance.TextNumericFormat.ExchangeRate;
            this.Column16.Width = 60;
            // 
            // Column17
            // 
            this.Column17.DataPropertyName = "Tien_Nt0";
            dataGridViewCellStyle5.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleRight;
            this.Column17.DefaultCellStyle = dataGridViewCellStyle5;
            this.Column17.HeaderText = "Tổng tiền";
            this.Column17.Name = "Column17";
            this.Column17.ReadOnly = true;
            this.Column17.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
            this.Column17.UserTextNumericFormat  = QMVnSoft.AppInstance.TextNumericFormat.ForeignAmount;
            this.Column17.Width = 70;
            // 
            // Column18
            // 
            this.Column18.DataPropertyName = "Tien_Nt1";
            dataGridViewCellStyle6.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleRight;
            this.Column18.DefaultCellStyle = dataGridViewCellStyle6;
            this.Column18.HeaderText = "Đã thực hiện";
            this.Column18.Name = "Column18";
            this.Column18.ReadOnly = true;
            this.Column18.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
            this.Column18.UserTextNumericFormat  = QMVnSoft.AppInstance.TextNumericFormat.ForeignAmount;
            this.Column18.Width = 70;
            // 
            // Column19
            // 
            this.Column19.DataPropertyName = "Tien_Nt2";
            dataGridViewCellStyle7.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleRight;
            this.Column19.DefaultCellStyle = dataGridViewCellStyle7;
            this.Column19.HeaderText = "Còn lại";
            this.Column19.Name = "Column19";
            this.Column19.ReadOnly = true;
            this.Column19.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
            this.Column19.UserTextNumericFormat  = QMVnSoft.AppInstance.TextNumericFormat.ForeignAmount;
            this.Column19.Width = 70;
            // 
            // Column20
            // 
            this.Column20.DataPropertyName = "Tien_Nt";
            dataGridViewCellStyle8.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleRight;
            this.Column20.DefaultCellStyle = dataGridViewCellStyle8;
            this.Column20.HeaderText = "Thanh toán";
            this.Column20.Name = "Column20";
            this.Column20.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
            this.Column20.UserTextNumericFormat  = QMVnSoft.AppInstance.TextNumericFormat.ForeignAmount;
            this.Column20.Width = 70;
            this.Column20.ZeroIsValid = true;
            // 
            // Column21
            // 
            this.Column21.DataPropertyName = "Marked";
            this.Column21.HeaderText = "";
            this.Column21.Name = "Column21";
            this.Column21.Resizable = System.Windows.Forms.DataGridViewTriState.False;
            this.Column21.Width = 20;
            // 
            // FormPaymentDetail
            // 
            this.ClientSize = new System.Drawing.Size(794, 534);
            this.Controls.Add(this.GridContainer);
            this.Controls.Add(this.Toolbars);
            this.MinimumSize = new System.Drawing.Size(802, 566);
            this.Name = "FormPaymentDetail";
            this.Text = "Chi tiết thanh toán và tỷ giá";
            this.Toolbars.ResumeLayout(false);
            this.Toolbars.PerformLayout();
            this.GridContainer.Panel1.ResumeLayout(false);
            this.GridContainer.Panel2.ResumeLayout(false);
            this.GridContainer.ResumeLayout(false);
            ((System.ComponentModel.ISupportInitialize)(this.grdMaster)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.grdDetail)).EndInit();
            this.ResumeLayout(false);
            this.PerformLayout();

        }

        private void oDetailHeader_OnCheckBoxClicked(bool state)
        {
            if ((this.oDetailTable != null) && (this.oDetailTable.Rows.Count != 0))
            {
                foreach (DataRow row in this.oDetailTable.Rows)
                {
                    if (row.RowState != DataRowState.Deleted)
                    {
                        if (state)
                        {
                            row["Tien_Nt"] = row["Tien_Nt2"];
                            row["Tien"] = row["Tien2"];
                            row["Marked"] = true;
                        }
                        else
                        {
                            row["Tien_Nt"] = 0;
                            row["Tien"] = 0;
                            row["Marked"] = false;
                        }
                    }
                }
                this.Sum();
            }
        }

        protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
        {
            if (keyData == Keys.Escape)
            {
                base.Close();
                return true;
            }
            if (keyData != (Keys.Control | Keys.Return))
            {
                return base.ProcessCmdKey(ref msg, keyData);
            }
            if (this.btnSave.Enabled)
            {
                this.Save();
            }
            base.Close();
            return true;
        }

        private void Save()
        {
            this.AppInvoiceParameters.AppInvoiceMethod.Save(this.AppInvoiceParameters.TransactionType, this.MasterDataRow, this.oDetailTable);
        }

        private void Sum()
        {
            decimal num = 0M;
            decimal num2 = 0M;
            foreach (DataRow row in this.oDetailTable.Rows)
            {
                if (row.RowState != DataRowState.Deleted)
                {
                    num += (decimal) row["Tien_Nt"];
                    num2 += (decimal) row["Tien"];
                }
            }
            this.MasterDataRow["Tien_Nt"] = num;
            this.MasterDataRow["Tien"] = num2;
            this.MasterDataRow.EndEdit();
        }

        [DefaultValue((string) null), Browsable(false), Category("Lister properties"), Description("The parameters that declare by system, user, invoice code.")]
        private AppInvoiceLib AppInvoiceParameters
        {
            get
            {
                if (this.oAppInvoiceLib == null)
                {
                    this.AppInvoiceParameters = new AppInvoiceLib();
                }
                return this.oAppInvoiceLib;
            }
            set
            {
                this.oAppInvoiceLib = value;
            }
        }

        private DataRow MasterDataRow
        {
            get
            {
                return this.oMasterRow;
            }
            set
            {
                if (this.oMasterRow != value)
                {
                    this.oMasterRow = value;
                    this.FillDetailData();
                }
            }
        }

        [Category("Lister properties"), DefaultValue(""), Browsable(false), Description("The current invoice order to edit or add.")]
        private string MasterInvoiceOrder
        {
            get
            {
                return this.is_MasterInvoiceOrder;
            }
            set
            {
                if ((this.is_MasterInvoiceOrder != value) && !string.IsNullOrEmpty(value))
                {
                    this.is_MasterInvoiceOrder = value;
                }
            }
        }
    }
}

